package com.fangshicai.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName RedisUrlInterceptor
 * @Description TODO
 * @Author fangshicai
 * @Date 2021/7/19 11:22
 */
@Component
public class RedisUrlInterceptor implements HandlerInterceptor {
    @Autowired
    StringRedisTemplate redisTemplate;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        System.out.println("当前的访问的url="+requestURI);
        ValueOperations<String, String> operations = redisTemplate.opsForValue();
        operations.increment(requestURI);
        System.out.println(operations.get(requestURI));
        return true;
    }
}
